let managePager = {}; //分页
managePager.managePageNum = 1;
let manageTotalPage; //总页码
let manageTotal;//总条数
managePullRefresh(managePager); //启用上拉下拉
let manageListNum = 0;//总条数

mui('body').on('tap', '.manageContextDivList', function () {
    let manageContextDivId = this.id;
    let manageNum = manageContextDivId.replace("manageContextDiv", "");
    let institutionId = '#institutionIdDiv' + manageNum;
    let institutionName = '#institutionNameDiv' + manageNum;
    let params = {
        "institutionId": $(institutionId).text(),
        "institutionName": $(institutionName).text()
    };
    WeKnow.location("violationRecord", params);
    WeKnow.closeLoading();


})


function managePullRefresh() {
    mui("#manageRefreshContainer").pullRefresh({
        up: {
            auto: true, //可选,默认false.首次加载自动下拉刷新一次
            contentdown: "下拉可以加载更多", //可选，在下拉可刷新状态时，下拉刷新控件上显示的标题内容
            contentover: "释放立即加载", //可选，在释放可刷新状态时，下拉刷新控件上显示的标题内容
            contentrefresh: "正在加载...", //可选，正在加载状态时，上拉加载控件上显示的标题内容
            contentnomore: '没 有 更 多 数 据 了', //可选，请求完毕若没有更多数据时显示的提醒内容；
            style: 'circle',//必选，下拉刷新样式，目前支持原生5+ ‘circle’ 样式
            color: '#2BD009', //可选，默认“#2BD009” 下拉刷新控件颜色
            height: '50px',//可选,默认50px.下拉刷新控件的高度,
            range: '100px', //可选 默认100px,控件可下拉拖拽的范围
            offset: '0px', //可选 默认0px,下拉刷新控件的起始位置
            callback: function () { //必选，刷新函数，根据具体业务来编写，比如通过ajax从服务器获取新数据；
                window.setTimeout(function () {
                    managePager.managePageSize = 10; //条数
                    manageGetData(managePager);
                }, 500);
            }
        },

    })
}

function manageGetData(params) {
    let managePageNum = params.managePageNum;
    let managePageSize = params.managePageSize;
    console.log(managePageNum)
    console.log(managePageSize)
    mui.ajax("violationRecord/manageViolationList", {
        data: {
            pageNum: managePageNum,
            pageSize: managePageSize,
            institutionId: localStorage.getItem("commonInstitutionId")
        },
        dataType: 'json', //服务器返回json格式数据
        type: 'post', //HTTP请求类型
        timeout: 10000, //超时时间设置为10秒；
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
        },
        success: function (data) {
            localStorage.setItem("commonInstitutionId",'');
            manageTotal = data.total;
            mui('#manageRefreshContainer').pullRefresh().endPullupToRefresh(true);
            if (data.errCode === 0) {
                let manageViolationList = data.manageViolationList;
                let manageViolationListId = document.getElementById('manageViolationListId');
                for (let i = 0; i < manageViolationList.length; i++) {
                    manageListNum++;
                    let html =
                        '<li class="mui-table-view-cell">' +
                        '<a id="manageContextDiv' + manageListNum + '" class="manageContextDivList mui-navigate-right">' +
                        '<span class="mui-badge mui-badge-danger">' + manageViolationList[i].violationNum + '</span>' +
                        '<span id="institutionIdDiv' + manageListNum + '" style="display: none">' + manageViolationList[i].institutionId + '</span>' +
                        '<span id="institutionNameDiv' + manageListNum + '" style="display: none">' + manageViolationList[i].name + '</span>' +
                        manageViolationList[i].name +
                        '</a>' +
                        '</li>';
                    manageViolationListId.innerHTML += html;
                }

                //这里很重要，这里获取页码 公式：总条数/每页显示条数
                manageTotalPage = manageTotal % managePager.managePageSize != 0 ? parseInt(manageTotal / managePager.managePageSize) + 1 : manageTotal / managePager.managePageSize;


                if (manageTotalPage == managePager.managePageNum||manageTotalPage==0) { //总页码等于当前页码，停止上拉下拉
                    mui('#manageRefreshContainer').pullRefresh().endPullupToRefresh(true);
                } else {
                    managePager.managePageNum = managePager.managePageNum + 1;
                    mui('#manageRefreshContainer').pullRefresh().refresh(true);
                }

            } else if (data.result == '0001') {

            }

        },
        error: function (xhr, type, errorThrown) {
            //异常处理；

        }
    })
}



